package com.ymatou.iapi.productmanager.testcase;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.reflect.TypeToken;
import com.ymatou.iapi.prodstock.parameter.LiveActivityDto;
import com.ymatou.iapi.productmanager.parameter.GetByProductIdBean;
import com.ymatou.iapi.productmanager.parameter.GetProductCatalogInfosBean;
import com.ymatou.iapi.productmanager.parameter.ProductCatalogDto;
import com.ymatou.iapi.productmanager.parameter.ProductCatalogDtoV2;
import com.ymatou.iapi.productmanager.parameter.WeChatCatalogDto;
import com.ymatou.iapi.productmanager.parameter.WeChatProductModel;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.product.MicroProductDto;
import com.ymatou.iapi.productmanager.parameter.product.MicroProductDtoV2;
import com.ymatou.iapi.productmanager.parameter.product.ProductDescSaveModel;
import com.ymatou.iapi.productmanager.service.GetByProductIdCall;
import com.ymatou.iapi.productmanager.service.GetPackageInfoByCatalogIdListCall;
import com.ymatou.iapi.productmanager.service.GetProductAndCatalogInfoCall;
import com.ymatou.iapi.productmanager.service.GetProductCatalogInfosCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.EnvSetup;
/**
*通过编号获取微店商品
*FreeMaker Template自动生成代码
*/
@TestSuite
@Ignore
public class Ts_GetByProductId{
	private static GetByProductIdBean getbyproductidBean;
	private static GetByProductIdCall getbyproductidCall;
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("通过编号获取微店商品(微店业务下架了)");
	}

	@Before
	public void caseUp() {
		getbyproductidBean=new GetByProductIdBean();
		getbyproductidCall=new GetByProductIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getbyproductidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Deprecated
	public void Tc_GetByProductId_001() {
		Logger.start(true,"通过编号获取微店商品");
		try {
			String productId = ProductManagerCallServiceV2.addmicroproduct(sellerId);
			getbyproductidBean.setProductId(productId);
			getbyproductidBean.setSellerId(sellerId);
			//checkMicroProductDto(getbyproductidBean);
			getbyproductidCall.setData(getbyproductidBean);
			getbyproductidCall.callService();	
			String sProduct=getbyproductidCall.getJsonObject().get("Data").getAsJsonObject().get("product").getAsJsonObject().toString();
			MicroProductDtoV2 mProduct = (MicroProductDtoV2)FormatUtil.GSONToObject(sProduct, new TypeToken<MicroProductDtoV2>(){}.getType());
			Logger.debug(mProduct.getCatalogList());
			if(mProduct != null){
				Logger.verifyEquals("200", getbyproductidCall.getString("Code"), "验证Code");
				GetProductCatalogInfosCall getProductCatalogInfosCall = new GetProductCatalogInfosCall();
				GetProductCatalogInfosBean getProductCatalogInfosBean = new GetProductCatalogInfosBean();
				getProductCatalogInfosBean.setProductId(getbyproductidBean.getProductId());
				getProductCatalogInfosBean.setUserId(getbyproductidBean.getSellerId());
				getProductCatalogInfosCall.setData(getProductCatalogInfosBean);
				getProductCatalogInfosCall.callService();
				List<ProductCatalogDtoV2> productCatalogInfos = getProductCatalogInfosCall.getProductCatalogInfos();
				Logger.verifyEquals(mProduct.getCatalogList().get(0).getCatalogId(), productCatalogInfos.get(0).getCatalogId(), "验证CatelogId");
				Logger.verifyEquals(mProduct.getCatalogList().get(0).getPrice(), productCatalogInfos.get(0).getPrice(), "验证price");
				Logger.verifyEquals(mProduct.getCatalogList().get(0).getStock(), productCatalogInfos.get(0).getStockNum(), "验证Stock");
				Logger.verifyEquals(mProduct.getProductId(), productCatalogInfos.get(0).getProductId(), "验证ProductId");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}